<?
require_once("cms/staff/om/StaffRolePeer.php");
require_once("cms/staff/om/StaffPeer.php");

class PHP_CMS_View_Helper_Recipients {

    public function recipients($newsletterId, $operator="NOT IN") {

        $c = new Criteria();

        $c->add(StaffPeer::STAFF_ID,
            "staff_id ". $operator .
            " (SELECT staff_id FROM newsletter_staff" .
            " WHERE received = 1" .
            " AND newsletter_id = '".mysql_real_escape_string($newsletterId)."')",
            Criteria::CUSTOM);

        if($operator == "NOT IN")
            $c->add(StaffPeer::LANGUAGE_CODE,
                "language_code IN ".
                " (SELECT language_code FROM newsletter_language" .
                " WHERE newsletter_id = '".mysql_real_escape_string($newsletterId)."')",
                Criteria::CUSTOM);

        $c->add(StaffPeer::NEWSLETTER, true);
        $c->add(StaffPeer::ACTIVE, true);
        
        return StaffPeer::doSelectJoinLanguage($c);

    }

}
?>